package com.nuc.seckill.service.impl;

import cn.hutool.core.lang.Assert;
import com.nuc.seckill.base.CommonQueryBean;
import com.nuc.seckill.dao.SeckillAdminDao;
import com.nuc.seckill.model.SeckillAdmin;
import com.nuc.seckill.service.AdminService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 石一歌
 * @date 2022-08-05 22:36
 */
@Service("adminService")
public class AdminServiceImpl implements AdminService {
    @Resource
    private SeckillAdminDao seckillAdminDao;

    @Override
    public List<SeckillAdmin> listAdmin() {
        return seckillAdminDao.list(null);
    }

    @Override
    public SeckillAdmin selectByPrimaryKey(Long id) {
        return seckillAdminDao.selectByPrimaryKey(id);
    }

    @Override
    public SeckillAdmin selectByUsername(String username) {
        Assert.notNull(username);
        SeckillAdmin item = new SeckillAdmin();
        item.setLoginName(username);
        List<SeckillAdmin> list = seckillAdminDao.list(item);
        if (!CollectionUtils.isEmpty(list)) {
            Assert.isTrue(list.size() == 1);
            return list.get(0);
        }
        return null;
    }

    @Override
    public int insert(SeckillAdmin record) {
        return seckillAdminDao.insert(record);
    }

    @Override
    public int updateByPrimaryKeySelective(SeckillAdmin record) {
        return seckillAdminDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<SeckillAdmin> list4Page(SeckillAdmin record, CommonQueryBean query) {
        return seckillAdminDao.list4Page(record, query);
    }

    @Override
    public long count(SeckillAdmin record) {
        return seckillAdminDao.count(record);
    }

    @Override
    public List<SeckillAdmin> list(SeckillAdmin record) {
        return seckillAdminDao.list(record);
    }
}
